﻿using Sprout.Schedule.Interfaces;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sprout.Schedule
{
    public static class ScheduleExtensions
    {
        /// <summary>
        /// 注入调度中心实例
        /// </summary>
        /// <param name="services"></param>
        /// <returns></returns>
        public static IServiceCollection AddSchedule(this IServiceCollection services)
        {
            new RegisterService().Register(services);

            return services;
        }
        /// <summary>
        /// 使用调度中心
        /// </summary>
        /// <param name="app"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseSchedule(this IApplicationBuilder app)
        {
            var jobManagerService = app.ApplicationServices.GetRequiredService<IJobManagerService>();
            jobManagerService.Initialize().Wait();

            return app;
        }
    }
}
